package com.shilun.springboot.hello_demo.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shilun.springboot.hello_demo.entity.User;
import com.shilun.springboot.hello_demo.service.UserService;
import com.shilun.springboot.hello_demo.test01.dao.UserMapperTest01;
import com.shilun.springboot.hello_demo.test01.service.UserServiceTest01;
import com.shilun.springboot.hello_demo.test02.dao.UserMapperTest02;
import com.shilun.springboot.hello_demo.test02.service.UserServiceTest02;

@Controller
public class HelloContorller {
	@Autowired
	private UserService userService;
	@Autowired
	private UserMapperTest01 userMapperTest01;
	@Autowired
	private UserMapperTest02 userMapperTest02;
	@Autowired
	private UserServiceTest01 userServiceTest01;
	@Autowired
	private UserServiceTest02 userServiceTest02;
	AtomicInteger sum=new AtomicInteger(0);
	@RequestMapping(path="/index")
	@ResponseBody
	public String index() {
		
		System.out.println("hello world,"+sum.incrementAndGet());
		return "hello world!";
	}
	
	@RequestMapping(path="/indexFreemarker")
	public String indexFreemarker(Map<String,Object> result) {
		result.put("name","shilun");
		result.put("sex",1);
		List<String> userlist =new ArrayList<String>();
		userlist.add("huyunhua");
		userlist.add("shiwenping");
		result.put("userlist", userlist);
		return "index";
	}
	
	@ResponseBody
	@RequestMapping(path="/createUser")
	public String createUser(String name, Integer age) {
		userService.createUser(name, age);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping(path="/findUser")
	public User findUser(Integer id) {
		return userService.findUser(id);
	}
	
	@ResponseBody
	@RequestMapping(path="/findUserByName")
	public User findUserByName(String name) {
		return userService.findUserByName(name);
	}
	
	@ResponseBody
	@RequestMapping("/insertTest001")
	public String insertTest001(String name, Integer age) {
		userServiceTest01.insertTest001(name, age);
		return "success";
	}
	
	@ResponseBody
	@RequestMapping("/insertTest002")
	public String insertTest002(String name, Integer age) {
		userServiceTest02.insertTest002(name, age);
		return "success";
	}
}
